<?php
//救援首页列表
function get_rescueList($status,$page,$page_size){
  $user_sex = array('未知','男','女');
  $rescue_status = array('待救援','救援中','完成救援','已评价','取消');
  if($status!=''){
     $where='r.status='.$status;
  }else{
     $where='1=1';
  }
  $sql="select count(*) from ".$GLOBALS['db']->table('rescue_log')." as r where $where";
  $count=$GLOBALS['db']->getOne("select count(*) from ".$GLOBALS['db']->table('rescue_log')." as r where $where");
  $page_count = ($count > 0) ? intval(ceil($count / $page_size)) : 1;
  $info=array();
  $sql = "SELECT u.*,r.id,r.user_describe,r.status,r.incident_desc FROM " .$GLOBALS['db']->table('rescue_log').
  " AS r LEFT JOIN ".$GLOBALS['db']->table('users').
  " AS u on r.user_id = u.user_id WHERE $where order by r.status=0 desc,r.add_time desc";
  $res=$GLOBALS['db']->selectLimit($sql, $page_size, ($page-1) * $page_size);
  $list=array();
  while ($v=$GLOBALS['db']->fetchRow($res)) {
    $info['log_id']=$v['id'];
   // $info['user_id']=$v['user_id'];
    $usericon = GZ_Api::get_url('/Mapi/public/images/usericon.png');
    $info['demander_headimg']=empty($v['headimg'])?$usericon:GZ_Api::get_url($v['headimg']);//头像
    $info['demander_name']=$v['user_name'];//姓名
    $info['demander_integral']=$v['user_integral'];
    $height=isset($v['height'])?$v['height']:'0.00';
    $weight=isset($v['weight'])?$v['weight']:'0.00';
    $label=json_decode($v['label']);
    $info['demander_style']=$user_sex[$v['sex']].'  '.$height.'cm  '. $weight.'kg';
    $info['rescue_status']=$rescue_status[$v['status']];//救援状态
    $info['status']=$v['status'];
    $info['incident_desc']=isset($v['incident_desc'])?$v['incident_desc']:'';//现场描述
    $list[] = $info;
  }
   $pager = array(
              "total"  => $count,  
              "count"  => count($list),
              "more"   => $page < $page_count ? 1 : 0
          );
   $result = array('list' =>$list, 'pager' => $pager);
   return $result;
}


//求助信息
function get_rescueInfo($id)
{
	$user_sex = array('未知','男','女');
	$rescue_status = array('待救援','救援中','完成救援','已评价','取消');

	$info = array();
	$sql = "SELECT u.user_name,u.user_integral,u.height,u.weight,u.age,u.headimg,u.sex".
	",r.id,r.user_describe,r.status,r.incident_desc,r.user_coordinate,rescue_coordinate FROM " .
	$GLOBALS['db']->table('rescue_log')." AS r LEFT JOIN ".$GLOBALS['db']->table('users').
	" AS u on r.user_id = u.user_id WHERE r.id='$id'";
	$res=$GLOBALS['db']->getRow($sql);
	
    if($res)
	{
		$usericon = GZ_Api::get_url('/Mapi/public/images/usericon.png');
		$height=!empty($res['height'])?$res['height']:'0.00';
        $weight=!empty($res['weight'])?$res['weight']:'0.00';
		
		//发布人及事件基本信息
		$info['log_id']				 = $res['id'];
		$info['demander_headimg']	 = empty($res['headimg'])?$usericon:$res['headimg'];//头像
		$info['demander_name']		 = $res['user_name'];//姓名
		$info['demander_integral']	 = $res['user_integral']; 
		$info['demander_style']		 = $res['age'].'岁  '.$user_sex[$res['sex']].'  '.$height.'cm  '. $weight.'kg';
		$info['rescue_status']		 = $rescue_status[$res['status']];//救援状态
		$info['status']				 = $res['status'];
		$info['incident_desc']		 = !empty($res['incident_desc'])?$res['incident_desc']:'';//现场描述
		
		//发布人坐标
		$info['user_coordinate'] ='';
		if(!empty($res['user_coordinate'])){ 
			$info['user_coordinate'] = json_decode($res['user_coordinate']);
		}
		//救援人坐标
		$info['rescue_coordinate'] ='';	
		if($res['status']>0 && $res['status']<0){ //已经有人救援（ 0未救援） 
			if(!empty($res['rescue_coordinate'])){ 
				$info['rescue_coordinate'] = json_decode($res['rescue_coordinate']);
			}
		}
		  
		return $info;
		
    }else{
		return false;
	}

}


 
?>